package service

import (
	"fmt"
	"ksd-social-api/commons/base/service"
	"ksd-social-api/commons/tools"
	"ksd-social-api/modules/platform/mapper"
	"ksd-social-api/modules/platform/model/vo"
	"ksd-social-api/utils"
	"ksd-social-api/utils/rdb"
)

var platformSystemMapper = mapper.PlatformSystemMapper{}

type PlatformSystemService struct {
	service.BaseService
}

/*
* 查找栏目
 */
func (mapper *PlatformSystemService) GetPlatformSystemService(systemId uint64) *vo.PlatformSystemVo {
	cacheKey := fmt.Sprintf("SYSTEM:MODEL:%d", systemId)
	jsonString, _ := rdb.RdbGet(cacheKey)
	platformSystemVo := vo.PlatformSystemVo{}
	tools.JsontoStruct(jsonString, &platformSystemVo)
	if platformSystemVo.Id == 0 {
		platformSystem, _ := platformSystemMapper.GetPlatformSystem(systemId)
		utils.CopyProperties(&platformSystemVo, platformSystem)
		rdb.RdbSetEX(cacheKey, tools.StructToJson(platformSystemVo), 60*60*24)
	}
	return &platformSystemVo
}
